﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace ModuleB.ViewModels
{
    public class ViewBViewModel : BindableBase
    {
        private ObservableCollection<string> _messages;
        public ObservableCollection<string> Messages
        {
            get { return _messages; }
            set { SetProperty(ref _messages, value); }
        }
        private readonly IEventAggregator _eventAggregator;
        public ViewBViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
            Messages = new ObservableCollection<string>();
            //_eventAggregator.GetEvent<PubSubEvent<string>>().Subscribe(mes => Messages.Add(mes));//接收消息
            //接收消息，并指定接收线程，添加过滤器
            _eventAggregator.GetEvent<PubSubEvent<string>>().Subscribe(mes => Messages.Add(mes), ThreadOption.PublisherThread,false,filter=>filter.Contains("A"));
        }
    }
}
